/**
 * @param {number[]} nums
 * @return {number}
 */
var jump = function(nums) {
  let max = 0, final = 0, count = 0;
  for(let i = 0; i < nums.length - 1; i++) {
    max = Math.max(max, i + nums[i]);
    if(i == final) {
      final = max;
      count++;
    }
  }
  return count;
};
let nums = [2,3,1,1,4];
console.log(jump(nums));
nums = [2,3,0,1,4];
console.log(jump(nums));
